#include <bits/stdc++.h>

#include "testlib.h"

#if defined(LOCAL)
#define DBG_MACRO_NO_WARNING
#include <dbg.hpp>
#else
#define dbg(x...) (0)
#endif

using namespace std;

using ll = long long;

// #define int ll
#define rep(i, f, t) for (int i = (f), ed##i = (t); i <= ed##i; ++i)
#define re(i, t) rep (i, 1, t)
#define per(i, t, f) for (int i = (t), ed##i = (f); i >= ed##i; --i)
#define ste(i, f, t, s) for (int i = (f), ed##i = (t); i <= ed##i; i += s)
#define nxt(i, f, g) for (int i = g.h[f]; i; i = g.e[i].n)
#define umod(x) ((x) >= mo && ((x) -= mo))
#define dmod(x) ((x) < 0 && ((x) += mo))
#define y1 y1__
#define fio(x) (freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout))

template <class T, class E>
__attribute__((always_inline)) inline void up(T &x, E &&y) {
  if (x < y) x = y;
}
template <class T, class E>
__attribute__((always_inline)) inline void down(T &x, E &&y) {
  if (y < x) x = y;
}

const int N = 1e6 + 9;
int a[N], n;
bool vis[N], fs = 1;

inline ll Ck(int *a, int K) {
  ll res = 0;
  re (i, n) {
    per (j, n, 1)
      if (a[j] == i) {
        res += n + 1 - j;
        if (res > K) return 0;
        reverse(a + j, a + n + 1);
        break;
      }
  }
  return res == K;
}

inline double Work() {
  n = inf.readInt(1, 1e6);
  re (i, n) vis[i] = 0;
  re (i, n) {
    a[i] = ouf.readInt(1, n);
    if (vis[a[i]]) quitf(_wa, "not a permutation");
    vis[a[i]] = 1;
  }
  int Q = min<double>(n * log2(n) + int(n / 12) + 5, 1668929), P = ouf.readInt(0, 10 * Q);
  if (!Ck(a, P)) quitf(_wa, "P not match");
  if (P <= Q) return 1;
  fs = 0;
  return 1 - log10(1. * P / Q);
}

signed main(signed argc, char **argv) {
  registerTestlibCmd(argc, argv);
  int T = inf.readInt(1, 1e9);
  double sco = 1;
  while (T--) down(sco, Work());
  if (fs) {
    quitf(_ok, "ok");
  }
  quitp(sco, "pc");
  return 0;
}
